package com.fandou.speech.asr.baidu;

import android.content.Context;

import com.baidu.aip.asrwakeup3.core.recog.listener.MessageStatusRecogListener;
import com.baidu.speech.asr.SpeechConstant;
import com.fandou.speech.asr.IRecognizer;

import java.util.Map;

public class OfflineRecognizer extends BaseRecognizer implements IRecognizer {
    /**
     * @param context
     */
    public OfflineRecognizer(Context context) {
        super(context, true);
    }


    @Override
    public void initialAsr(Context context) {
        super.initialAsr(context);
    }

    @Override
    public void releaseAsr() {
        super.release();
    }

    @Override
    public void startAsrCN(String outFile, MessageStatusRecogListener.OnAsrListener onAsrListener) {
        //PID 15361 普通话	搜索模型	无标点	支持
        Map<String, Object> params = fetchParams(15361, outFile);
        start(params, onAsrListener);
    }

    @Override
    public void startAsrEN(String outFile, MessageStatusRecogListener.OnAsrListener onAsrListener) {
        Map<String, Object> params = fetchParams(1736, outFile);

        params.put(SpeechConstant.VAD_ENDPOINT_TIMEOUT, 500); // >0（毫秒），默认800ms	在线	高级	不开启长语音。开启VAD尾点检测，即静音判断的毫秒数。建议设置800ms-3000ms
        params.put(SpeechConstant.VAD, SpeechConstant.VAD_DNN);
        // params.put(SpeechConstant.NLU, "enable");
        // params.put(SpeechConstant.PROP ,20000);

        if (enableOffline) {
            params.put(SpeechConstant.DECODER, 2);
        }

        start(params, onAsrListener);  // start recognize now
    }

    @Override
    public void stopAsr() {
        super.cancel();
    }

}
